package com.rt.easyjava.common.utils.network;

import lombok.extern.slf4j.Slf4j;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;

@Slf4j
public class WsdlUtils {

    private static WsdlUtils wsdlUtils;

    private WsdlUtils() {
    }

    static {
        if (null == wsdlUtils) {
            wsdlUtils = new WsdlUtils();
        }
    }

    public static WsdlUtils getInstance() {
        return wsdlUtils;
    }

    public String getData(String wsdlUrl, String data, String methodName) throws Exception {
        JaxWsDynamicClientFactory dynamicClientFactory = JaxWsDynamicClientFactory.newInstance();
        Client client = dynamicClientFactory.createClient(wsdlUrl);
        Object[] res = client.invoke(methodName, data);
        if (null != res) {
            return res[0].toString();
        } else {
            log.error("【WSDL调用】- 未接收到返回值");
            return null;
        }
    }
}
